/**
 * @author eric.schulte
 */
 
import mx.utils.Delegate;
import com.mrmny.util.xml.XMLSA;
import com.mrmny.util.movieclip.IMovieClipHelper;
import com.senocular.ColorFader;
import com.quasimondo.ColorMatrix;
import flash.filters.ColorMatrixFilter;
class com.mrmny.util.movieclip.MovieClipHelper extends MovieClip implements IMovieClipHelper{
	
	private var _id:String;
	private var _xml:XMLSA;
	private var _cf:ColorFader;
	private var _tween:Object;
	private var _saturation:Number=100;
	private var _contrast:Number=0;
	private var _cm:ColorMatrix;
	private var _cmf:ColorMatrixFilter;
	private var _hit;
	
	public function MovieClipHelper() {
		super();
		__init();
	}
	private function __init():Void{
		_tween=new Object();
	}
	private function _onXMLLoaded():Void{
		
	}
	public function get xml():XMLSA{
		return _xml;	
	}
	public function set xml(val:XMLSA):Void{
		_xml=val;
		_onXMLLoaded();
	}
	public function moveTo($x:Number,$y:Number):Void{
		_x=$x;
		_y=$y;
	}
	public function fadeTo($colour:Number,$time:Number):Void{
		
		if(_cf==undefined){
			_cf=new ColorFader(this);	
		}
		_cf.fadeTo($colour,$time);
	}
	private function _enableMouseEvents($hit):Void{
		if($hit){
			_hit=$hit;
			$hit.onPress=Delegate.create(this,_press);
			$hit.onRollOver=Delegate.create(this,_over);
			$hit.onRollOut=Delegate.create(this,_out);
		}else{
			this.onPress=Delegate.create(this,_press);
			this.onRollOver=Delegate.create(this,_over);
			this.onRollOut=Delegate.create(this,_out);			
		}
	
	}
	private function _over():Void{
		
	}
	private function _out():Void{
		
	}
	private function _press():Void{
		
	}
	private function _adjustColorFilter():Void{
		_cm=new ColorMatrix();
		_cm.adjustContrast(_contrast/100);
		_cm.adjustSaturation(_saturation/100);
		_cmf=new ColorMatrixFilter(_cm.matrix);
		this.filters=[_cmf];
	}
	private function _disableMouseEvents():Void{
		if(_hit){
			delete(_hit.onPress);
			delete(_hit.onRollOver);
			delete(_hit.onRollOut);
		}else{
			delete(this.onPress);
			delete(this.onRollOver);
			delete(this.onRollOut);			
		}

	}
	public function get saturation():Number{
		return _saturation;	
	}
	public function set saturation($saturation:Number):Void{
		_saturation=$saturation;
		_adjustColorFilter();	
	}
	public function get contrast():Number{
		return _contrast;	
	}
	public function set contrast($contrast:Number):Void{
		_contrast=$contrast;
		_adjustColorFilter();	
	}
	
	
}